/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 *
 * @author amega
 */
@Entity
@Table(name="users" , catalog="ors", schema="")
@NamedQueries({
    @NamedQuery(name="Users.findById", query = "SELECT u FROM user u WHERE u.id_user = :id_user" )
})
public class Users extends BaseEntity implements Serializable {
    
    
    
    @Column(name="name")
    private String name;
    @Column(name="email", nullable=false)
    private String email;
    @Column(name="password", nullable=false)
    private String password;
    @Column(name="phone", nullable=false, length=255)
    private String phone;
    @Column(name="role",nullable=false)
    private UserType roleuser;

    @OneToMany(mappedBy="id_user")
    private List<Comments> listCommnents;
    @OneToMany(mappedBy="id_user_from")
    private List<Messages> listMessage;
    
    @OneToMany(mappedBy="id_user")
    private List<Orders> listOrders;
    @OneToMany(mappedBy="id_user")
    private List<Questions> listQuestions;
    

    
    public Users() {
    }
    
    public Users(Long id) {
        this.id = id;
    } 
    
    public Users(String name,String email,String password,String phone,UserType roleuser) {
        this.name = name;
        this.email = email;
        this.password = password;
        this.phone = phone;
        this.roleuser = roleuser;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public UserType getRoleuser() {
        return roleuser;
    }

    public void setRoleuser(UserType roleuser) {
        this.roleuser = roleuser;
    }
    
     public List<Comments> getListCommnents() {
        return listCommnents;
    }

    public void setListCommnents(List<Comments> listCommnents) {
        this.listCommnents = listCommnents;
    }

    public List<Messages> getListMessage() {
        return listMessage;
    }

    public void setListMessage(List<Messages> listMessage) {
        this.listMessage = listMessage;
    }

    public List<Orders> getListOrders() {
        return listOrders;
    }

    public void setListOrders(List<Orders> listOrders) {
        this.listOrders = listOrders;
    }

    public List<Questions> getListQuestions() {
        return listQuestions;
    }

    public void setListQuestions(List<Questions> listQuestions) {
        this.listQuestions = listQuestions;
    }
    
    public void addComment(Comments comment) {
        if (null == comment) return;
        if (null == this.listCommnents) {
            this.listCommnents = new ArrayList<Comments>();
        }
        this.listCommnents.add(comment);
    }
         
    public boolean deleteComment(Comments comment) {
        if (null != this.listCommnents && null != comment) {
            return listCommnents.remove(comment);
        } else {
            return false;
        }
    }
    
     public void addMessage(Messages message) {
        if (null == message) return;
        if (null == this.listMessage) {
            this.listMessage = new ArrayList<Messages>();
        }
        this.listMessage.add(message);
    }
         
    public boolean deleteMessage(Messages message) {
        if (null != this.listMessage && null != message) {
            return listMessage.remove(message);
        } else {
            return false;
        }
    }
    
    
    public void addOrder(Orders order) {
        if (null == order) return;
        if (null == this.listOrders) {
            this.listOrders = new ArrayList<Orders>();
        }
        this.listOrders.add(order);
    }
         
    public boolean deleteOrder(Orders order) {
        if (null != this.listOrders && null != order) {
            return listOrders.remove(order);
        } else {
            return false;
        }
    }
    
    
    public void addQuestion(Questions question) {
        if (null == question) return;;
        if (null == this.listQuestions) {
            this.listQuestions = new ArrayList<Questions>();
        }
        this.listQuestions.add(question);
    }
    
    public boolean deleteQuestion(Questions question) {
        if (null != this.listQuestions && null != question) {
            return this.listQuestions.remove(question);
        } else {
            return false;
        }
    } 
    

    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Users)) {
            return false;
        }
        Users other = (Users) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "models.Users[ id=" + id + " ]";
    }
    
}
